package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2022/1/13 13:13
 * @description：https://leetcode-cn.com/problems/largest-number-at-least-twice-of-others/
 */
public class 至少是其他数字两倍的最大数 {
    @Test
    public void test() {
        Solution solution = new Solution();
    }


    class Solution {
        public int dominantIndex(int[] nums) {
            int pre = 0, max = 0, maxIdx = 0;
            for (int i = 0; i < nums.length; i++) {
                if (nums[i] > max) {
                    pre = max;
                    max = nums[i];
                    maxIdx = i;
                } else if (nums[i] > pre) {
                    pre = nums[i];
                }
            }
            return max >= pre * 2 ? maxIdx : -1;
        }
    }
}
